﻿<?php
	include("mysql.php");
	$tl_title=addslashes($_POST['tl_title']);
	$tl_img="anh/".$_FILES["file"]["name"];
	$tl_des=addslashes($_POST['tl_des']);
	$tl_link ="upload/".$_FILES["file"]["name"];
	$tl_price=addslashes($_POST['tl_price']);
	$m_id=addslashes($_POST['m_id']);
	$pl_id=addslashes($_POST['pl_id']);
	if($_GET['act']=="do"){
		if($_FILES["file"]["error"] > 0){
			echo "Error: " . $_FILES["file"]["error"] . "<br />";
			echo "Có lỗi trong quá trình upload, vui lòng liên hệ BQT";
			exit();
		}
		if(!empty($tl_title)){
			$sql_up=mysql_query("INSERT INTO tailieu(tl_title,tl_img,tl_des,tl_link,tl_price,m_id,pl_id,tl_date) VALUES ('{$tl_title}','{$tl_img}','{$tl_des}',
														'{$tl_link}','{$tl_price}','{$m_id}','{$pl_id}',NOW())");
			if($sql_up){
				$upload=move_uploaded_file($_FILES["file"]["tmp_name"],
						"upload/".$_FILES["file"]["name"]);	
				$upload_anh=move_uploaded_file($_FILES["file"]["tmp_name"],
						"anh/".$_FILES["file"]["name"]);			
				echo"Them thanh cong";
			}
			
			echo "Upload : " . $_FILES["file"]["name"] . "<br />";
			echo "Định dạng : " . $_FILES["file"]["type"] . "<br />";
			echo "Kích thước : " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
			echo "Tên tài liệu : "."<b>".$_POST['tl_title']."</b>";
			echo "</br>Thể loại :"."<b>".$_POST['theloai']."</b>";	
			echo"</br>Ảnh :"."<b>".$_POST['tl_img']."<b>";
			echo"</br> Upload thành công.Click vào đây để về trang chủ:<a href='index.php'>Trang chủ</a>";		

		}
	}	
?>
<form action="upload.php?act=do" method="post" enctype="multipart/form-data">
	<table class="upload">
		<tr>
			<td><input type="file" name="file"></td>
		</tr>
		
		<tr>
			<td><input type="text" name="tl_title"></td>
		</tr>
		
		<tr>
			<td><input type="file" name="tl_img" value="hinh anh"></td>
		</tr>	
		
		<tr>
			<td><input type="text" name="tl_des" value="Trich mot doan noi dung cua tai lieu"></td>
		</tr>
		
		<tr>
			<td><select name="m_id"><option value="0">Lua chon menu</option>
				<?php
					$select_menu=mysql_query("select * from menu order by m_id");
					while($row_menus=mysql_fetch_array($select_menu)){
						echo"<option value='".$row_menus['m_id']."'>".$row_menus['m_title']."</option>";
					}
				?>
				</select>
				
				<select name="pl_id"><option value="">Lua chon danh muc</option>
					<?php
						$select_phanloai=mysql_query("select * from phanloai order by pl_id");
						while($row_pl=mysql_fetch_array($select_phanloai)){
							echo"<option value='".$row_pl['pl_id']."'>".$row_pl['pl_title']."</option>";
						}
					?>
				</select>
			</td>		
		</tr>
		
		<tr>
			<td><input type="text" name="tl_price"></td>
		</tr>
		
		<td>	
			<input type="submit" name="submit" value="Upload">
			<input type="reset" name="B2" value="Nhap lai">	
		</td>
	</table>
</form>